using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Linq.Expressions;
using Magiq.Support;
using MirrorMirror;

namespace Magiq.Query
{
    public class QueryInfo<T, TChild>
    {
        private IEnumerable<TChild> compiled;
        public QueryInfo(T item, Expression<Func<T,IEnumerable<TChild>>> collectionExpression)
        {
            Item = item;
            CollectionExpression = collectionExpression;
        }

        public Expression<Func<T, IEnumerable<TChild>>> CollectionExpression { get; private set; }
        public T Item { get; private set; }

        public IEnumerable<TChild> Compiled
        {
            get
            {
                if (compiled == null)
                {
                    compiled = CollectionExpression.Compile()(Item);
                    //compiled = Item.Get<IEnumerable<TChild>>(CollectionExpression.ToMemberExpression().Member.Name);
                }
                
                return compiled;
            }
        }
    }
}